package com.csx.governance.traffic.core.interceptor.inbound;

import com.csx.governance.traffic.core.TransportableAttributes;
import com.csx.governance.traffic.core.constants.TrafficAttributeConstants;
import com.csx.governance.traffic.core.context.TrafficRequest;
import com.csx.governance.traffic.core.context.TrafficResponse;
import org.springframework.core.Ordered;

/**
 * 该类将请求中某些属性取出来，并将其放入到 TransportableAttributes 中
 * @author cuisongxu
 * @date 2023/4/2 13:12
 */
public class TransportAttributesPutInboundHandlerInterceptor extends TrafficAbstractInboundHandlerInterceptor {

    @Override
    public int getOrder() {
        return Ordered.LOWEST_PRECEDENCE - 1000;
    }

    // TODO 后续考虑通过读取配置的方式获取需要透传的属性名
    @Override
    public boolean preHandle(TrafficRequest request, TrafficResponse response) {
        String swimLaneId = request.getAttribute(TrafficAttributeConstants.SWIM_LANE, String.class);
        TransportableAttributes.setAttribute(TrafficAttributeConstants.SWIM_LANE, swimLaneId);
        return super.preHandle(request, response);
    }
}
